home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / MDP-80 Folder / Documentation / Assembler Manual.text < prev    next >
Encoding:
Text File  |  1994-09-12  |  36.6 KB  |  960 lines  |  [TEXT/ALFA]

  1.  
  2.  
  3.                      MDP-8008 Assembler User's Manual
  4.  
  5.  
  6.                                    by
  7.  
  8.                             Ronald T. Kneusel
  9.  
  10.                                   1994
  11.  
  12.  
  13.  
  14. The MDP-8008 assembler was designed to ease the task of creating programs for 
  15. the MDP-80 simulator.  This user manual describes the assembler and how to use 
  16. it to create your own assembly language programs.  Basic knowledge of 
  17. programming at the machine or assembler level is assumed.
  18.  
  19. This manual, the MDP-8008 assembler, MDP-80 simulator and manual, tutorials, and 
  20. sample programs are copyright, 1994, by Ronald T. Kneusel.  Unauthorized 
  21. reproduction or modification in any form is prohibited without prior written 
  22. consent.
  23.  
  24. THE AUTHOR ASSUMES NO RESPONSIBILITY FOR ANY DAMAGE SUSTAINED FROM THE 
  25. USE OF THIS PROGRAM AND MANUAL.  NO WARRANTY IS GIVEN, EITHER EXPLICITLY 
  26. OR IMPLICITLY.  CAVEAT EMPTOR.
  27.  
  28.  
  29. • Chapter 1  -  Introduction
  30.  
  31.  
  32. In the beginning there was machine code, and it was not good.  Machine 
  33. code is difficult to write, hard to modify, and nearly impossible to 
  34. debug.  Life was miserable and the power of the computer was locked in the 
  35. hands of the elite few who could manipulate the machine at its own 
  36. level.  Enter assembly language.  Assembly language is basically a 
  37. substitution of (relatively) easy to remember mnemonics (alphanumeric 
  38. codes that give some indication of the purpose of an instruction) for the 
  39. difficult to remember numerical instruction codes.  Unlike high level 
  40. computer languages, there is a one-to-one correspondence between an 
  41. assembly language instruction and an actual machine instruction.  Not 
  42. only are individual machine instructions difficult to remember but the 
  43. numerical value for a particular instruction varies from one address
  44. mode to another.  An assembler allows the programmer to specify both an 
  45. instruction and its address mode in an easy to read form.
  46.  
  47. The assembler described below will be of primary use to you as you work 
  48. through the tutorials and on to creating your own programs.  This manual 
  49. assumes a basic familiarity with assembly language programming.  If this 
  50. is your initial attempt at assembly language it will be helpful to work 
  51. through the tutorial first.
  52.  
  53. •• Features
  54.  
  55. The MDP-8008 assembler is a fully functional, though simple, two pass assembler.  
  56. Some of its features are listed below:
  57.  
  58.    * Free-form source code format
  59.     
  60.    * Unlimited source code size
  61.     
  62.    * Unlimited label length
  63.     
  64.    * Optional assembly listing and symbol table
  65.     
  66.    * Inclusion of useful pseudo instructions, ASC and HEX
  67.     
  68.    * Special address operators $>$ and $<$
  69.     
  70.    * Ability to include header files with standard equates
  71.  
  72.  
  73. •• Restrictions
  74.  
  75. In order to preserve the simple nature of the assembler some restrictions 
  76. apply.  These are:
  77.  
  78.    * No operand arithmetic
  79.     
  80.    * All numbers assumed to be hexadecimal
  81.     
  82.    * Only a single \#ORG permitted per file
  83.     
  84.    * The special address operators $>$ and $<$ are restricted to labels only
  85.     
  86.    * All branches are assembled as absolute, not relative
  87.     
  88.    * All labels assemble as two bytes
  89.     
  90.    * Zero page instructions assembled only if address is a number
  91.  
  92.  
  93.  
  94. •• A Sample Session
  95.  
  96.  
  97. The assembler does not contain a built in text editor.  In order to 
  98. create programs you will need some form of external text editor.  
  99. If all else fails you can use _TeachText_ which was included with your 
  100. Macintosh.  A standard word processor can be used provided the file is saved 
  101. as a TEXT file.  If you are using System 7 or Multifinder, you can run both 
  102. the assembler and your text editor and quickly switch between the two.  
  103. This creates a rapid development environment in which changes to the source 
  104. program can be quickly assembled and errors corrected.
  105.  
  106.  
  107. ••• Creating `Hello.ASM'
  108.  
  109. Using a text editor, enter the following sample assembly language 
  110. program and save it as `Hello.ASM'. This is the famous "Hello, world!" 
  111. example.
  112.  
  113.  
  114. ;  Hello.world  -  Displays "Hello, world!"
  115.  
  116. #include std.equ    ; Standard monitor equates
  117.  
  118. #org  1000          ; Program begins at address 1000 (hexadecimal)
  119.  
  120. ; Begin program
  121.  
  122.          lda >message              ; put high byte of MESSAGE in A
  123.          ldx <message              ; put low byte of MESSAGE in X
  124.          jsr _print                ; monitor routine to print string
  125.          rts                       ; pointed to by A and X
  126. .message asc 'Hello, world!'       ; here is the string
  127.          hex 0d00                  ; 0d is return, 00 ends the string
  128.  
  129. ; end
  130.  
  131.  
  132.  
  133. ••• Assembling `Hello.ASM'
  134.  
  135. Open the assembler application and select "Assemble File" from  the 
  136. "File" menu.  A standard Macintosh open file dialog will appear.  Use 
  137. it to select the file _Hello.ASM_.  The assembler will respond with 
  138. another dialog box asking for a name to give to the assembled output file.  
  139. Notice that the assembler has changed the .ASM suffix into .OBJ, this is 
  140. the standard suffix for an assembled file.  Other possible suffixes 
  141. include .LST for an assembly listing and .SYM for a symbol table.  
  142. Clicking the _Okay_ button will cause the file to be assembled.  
  143.  
  144. During the first pass the assembler locates the labels used by 
  145. the program.  In the second pass it generates the output file.  A `.' 
  146. is displayed for each line of the source program that is read.  If there 
  147. are no assembly errors it will report that assembly is complete and 
  148. indicate the number of lines in the source file, as well as the starting and
  149. ending memory addresses.  Errors are indicated by the corresponding line 
  150. number in the source program.  Assuming no errors, the program is assembled 
  151. and the file Hello.OBJ is ready to be loaded into the simulator and run.
  152.  
  153.  
  154. ••• Modifying `Hello.ASM'
  155.  
  156. Suppose we want to modify our program to print the text in the middle of
  157. a clear screen.  To accomplish this we will need to use two new subroutines, 
  158. one in the system monitor and the other of our own design.  After the last 
  159. line in the file include the following code:
  160.  
  161. .down    lda #0d                   ; the return character
  162. .again   jsr _cout                 ; monitor print character routine
  163.          dey                       ; decrease count
  164.          bne again                 ; if not zero print again
  165.          rts
  166.  
  167. This will print Y blank lines where Y is the current value of the Y 
  168. register.  We will call this routine with Y set to 10 after clearing the 
  169. screen.   After the begin program comment include the following:
  170.  
  171.          lda #0c                   ; 0C=12, clears the screen
  172.          jsr _cout                 ; monitor routine
  173.          ldy #0a                   ; load 10 into Y
  174.          jsr down                  ; and call our routine
  175.  
  176. Lastly, we want to print 35 blank spaces before displaying the message.  
  177. Fortunately, there exists a monitor routine to do this for us.  After the 
  178. call to the subroutine _down_ enter the following:
  179.  
  180.          ldx #23                   ; X holds count
  181.          jsr _blanks               ; print the blanks
  182.  
  183. The final modified program should appear as below:
  184.  
  185.  
  186. ;  Hello.world  -  Displays "Hello, world!"
  187.  
  188. #include std.equ    ; Standard monitor equates
  189.  
  190. #org  1000          ; Program begins at address 1000 (hexadecimal)
  191.  
  192. ; Begin program
  193.  
  194.          lda #0c                   ; 0C=12, clears the screen
  195.          jsr _cout                 ; monitor routine
  196.          ldy #0a                   ; load 10 into Y
  197.          jsr down                  ; and call our routine
  198.          ldx #23                   ; X holds count
  199.          jsr _blanks               ; print the blanks
  200.          lda >message              ; put high byte of MESSAGE in A
  201.          ldx <message              ; put low byte of MESSAGE in X
  202.          jsr _print                ; monitor routine to print string
  203.          rts                       ; pointed to by A and X
  204. .message asc 'Hello, world!'       ; here is the string
  205.          hex 0d00                  ; 0d is return, 00 ends the string
  206. .down    lda #0d                   ; the return character
  207. .again   jsr _cout                 ; monitor print character routine
  208.          dey                       ; decrease count
  209.          bne again                 ; if not zero print again
  210.          rts
  211.  
  212. ; end
  213.  
  214. Using the same procedure as before, assemble the modified file replacing 
  215. the earlier version of `Hello.OBJ'.  Load this version into the simulator 
  216. and run it.
  217.  
  218.  
  219.  
  220. • Chapter 2  -  The Assembler Program
  221.  
  222. The assembler is completely menu driven and is designed to be as simple 
  223. as possible.  There are three menus: File, Edit, and Options.  The Edit 
  224. menu is for desk accessories and is disabled. 
  225.  
  226. •• The File Menu
  227.  
  228. The File menu is used to choose a file to assemble or to quit the 
  229. application.  The first menu item `Assemble File...' will bring up a 
  230. standard Macintosh dialog box allowing the user to select a source file 
  231. to assemble.  If the file selected ends with `.ASM' the assembler will 
  232. strip it before appending any other extensions.
  233.  
  234. •• The Options Menu
  235.  
  236. Use the "Options" menu to select where, or if, the assembler will send 
  237. the assembly listing or symbol table.  The currently active options are 
  238. indicated by a checkmark.  Initially, the assembler is set for no listing 
  239. and no symbol table.  Selecting any of the options activates it and places 
  240. a checkmark next to it. Only one option can be active at a time.  
  241.  
  242. •• The Assembly Listing
  243.  
  244. The assembly listing contains both the original source code and the 
  245. machine code.  An assembly listing for the file `Hello.ASM' appears as, 
  246.  
  247.  
  248.    1-             ;  HELLO.WORLD  -  DISPLAYS "HELLO, WORLD!"
  249.    2-            
  250.    3-             #INCLUDE STD.EQU  ; STANDARD MONITOR EQUATES
  251.    4-            
  252.    5-             #ORG  1000        ; PROGRAM BEGINS AT ADDRESS 1000 (HEX)
  253.    6-            
  254.    7-             ; BEGIN PROGRAM
  255.    8-            
  256.    9-  1000: A9 0C       LDA #0C             ; 0C=12, CLEARS THE SCREEN
  257.   10-  1002: 20 F8 76    JSR _COUT           ; MONITOR ROUTINE
  258.   11-  1005: A6 0A       LDY #0A             ; LOAD 10 INTO Y
  259.   12-  1007: 20 10 26    JSR DOWN            ; AND CALL OUR ROUTINE
  260.   13-  100A: A8 23       LDX #23             ; X HOLDS COUNT
  261.   14-  100C: 20 FF D8    JSR _BLANKS         ; PRINT THE BLANKS
  262.   15-  100F: A9 10       LDA >MESSAGE        ; PUT HIGH BYTE OF MESSAGE IN A
  263.   16-  1011: A8 17       LDX <MESSAGE        ; PUT LOW BYTE OF MESSAGE IN X
  264.   17-  1013: 20 F8 D2    JSR _PRINT          ; MONITOR ROUTINE TO PRINT STRING
  265.   18-  1016: 60          RTS                 ; POINTED TO BY A AND X
  266.   19-  1017: 48656C6C6F2C20776F726C6421   .MESSAGE ASC 'Hello, world!'   ; HERE IS THE STRING
  267.   20-  1024: 0D00   HEX 0D00                 ; 0D IS RETURN, 00 ENDS THE STRING
  268.   21-  1026: A9 0D       .DOWN    LDA #0D    ; THE RETURN CHARACTER
  269.   22-  1028: 20 F8 76    .AGAIN   JSR _COUT  ; MONITOR PRINT CHARACTER ROUTINE
  270.   23-  102B: C5          DEY                 ; DECREASE COUNT
  271.   24-  102C: D1 10 28    BNE AGAIN           ; IF NOT ZERO PRINT AGAIN
  272.   25-  102F: 60          RTS
  273.   26-            
  274.   27-             ; END
  275.   28-            
  276.  
  277. The line number is followed by the actual address and machine code that 
  278. correspond to the instruction listed.  Note that all assembler input is 
  279. mapped to uppercase characters.  
  280.  
  281. The options concerning the assembly listing are straightforward.  The 
  282. listing can be sent to the terminal (List to terminal), to a file 
  283. on disk (List to file), or directly to the printer (List to printer).  
  284. Listing directly to the printer is rather slow, so be patient.
  285.  
  286. If _List to file_ is selected the assembler will create a file with the 
  287. same name as the source file plus a `.LST' extension.  This file is a 
  288. standard TEXT file and has the format given above.  You can read this file 
  289. into any text editor, though the file will have the creator 
  290. `ALFA' and will look for the Shareware editor Alpha by Peter Keleher when 
  291. double-clicked.  Alpha is an excellent editor and is highly recommended as 
  292. a companion to the assembler and simulator.
  293.  
  294. ••• The Symbol Table
  295.  
  296. The symbol table is a list of the labels defined in an assembly language
  297. program.  Labels are created in one of three ways: (1) by an #EQU 
  298. statement, (2) by prefixing an instruction line with `.label' where 
  299. `label' is the label that will reference that line, or (3) by using an 
  300. #INCLUDE to include a file of equates (such as the file STD.EQU which 
  301. contains the equates for the system monitor).  During the first pass of 
  302. the assembler all labels are identified and the location they reference 
  303. is determined.  The second pass then uses this information to fill in the 
  304. proper addresses for creating the output file.
  305.  
  306. The symbol table for the program `Hello.ASM' appears as,
  307.  
  308.  
  309. Symbol Table
  310.  
  311. [0200] KOUT        [0201] CSTB        [0202] KBDS        [0203] KEYB        
  312. [0100] STAK        [FFFD] COLD        [FFFA] BREAK       [0300] TEXT        
  313. [F800] _MON        [F830] VERSION     [F832] _MON1       [F851] _BRK        
  314. [F876] _COUT       [F87D] _KEYIN      [F884] _INPUT      [F889] _INPUT1     
  315. [F8D2] _PRINT      [F8D6] PRINT1      [F8E9] _PRINTHEX   [F920] _PRINTWORD  
  316. [F928] _UPPER      [F92C] _UPPER1     [F952] _KILLB      [F956] _KILLB1     
  317. [F989] _LENGTH     [F99B] _MAKEHEX    [F9C3] _MAKEBYTE   [F9DD] _NUMBER     
  318. [F9E1] _NUMBER1    [FA50] _ADD16      [FF7F] _REG        [FFD8] _BLANKS     
  319. [1017] MESSAGE     [1026] DOWN        [1028] AGAIN       
  320.  
  321.  
  322. Note that there are far more symbols present than the few defined in the 
  323. program itself.  This is due to the #INCLUDE STD.EQU statement which 
  324. includes the symbols for the more important and useful system monitor 
  325. routines.  The assembler does not differentiate between #INCLUDEd symbols 
  326. and symbols created in the program.  The value in square brackets is the 
  327. address associated with the symbol whose name follows.  By convention, all 
  328. system monitor subroutines have the `_' character as the first character in 
  329. the symbol name.  The individual subroutines are discussed in _The System 
  330. Monitor via Assembly Language_ chapter.
  331.  
  332. Symbol table options include sending the table to the terminal (Table to 
  333. terminal), to a file (Table to file), or to the printer (Table to printer).  
  334. As with the assembly listing, sending the table to the printer is rather slow.
  335.  
  336. If "Table to file" is selected and there is no assembly listing or 
  337. the listing is not being sent to a file the assembler will prompt you for 
  338. a file name.  By default it will choose the name of the source file plus 
  339. a `.SYM' extension.  If both "List to file" and "Table to file" are selected 
  340. the symbol table will be automatically appended to the end of the listing file 
  341. and no `.SYM' file will be created.
  342.  
  343.  
  344. • Chapter 3  -  Assembler Instruction Format
  345.  
  346. An assembly language source file will contain several elements, some 
  347. mandatory, others optional:
  348.  
  349.   *  Assembler directives
  350.   *  Labels (or symbols)
  351.   *  Mnemonics (instruction codes)
  352.   *  Operands
  353.   *  Comments and white space
  354.   *  Special forms
  355.  
  356.  
  357. •• Assembler directives
  358.  
  359. The MDP-8008 assembler understands only three types of directives: 
  360. #EQU, #ORG, and #INCLUDE.  These are not instructions but are a way 
  361. of providing the assembler with information about the source file.  They 
  362. typically appear near the beginning of a program before any actual 
  363. instructions.  This is not a requirement, however, since the assembler uses
  364. two passes the directives may appear anywhere without restriction.
  365.  
  366. •• #EQU
  367.  
  368. The #EQU (equate) directive may appear anywhere and is used to bind an address 
  369. to a symbol.  The format is:
  370.  
  371.                      #EQU   `label'   `address'
  372.  
  373. Where `label' is the symbol being defined and `address' is the address 
  374. bound to `label'.  The symbol must begin with a letter of the alphabet or 
  375. the `_' character, which, by convention, is reserved for system monitor 
  376. routines. If a symbol is defined more than once an assembler warning 
  377. error is generated and the initial binding is used.  This usually results 
  378. in garbage when the program is run.  The address bound to the symbol must 
  379. be a valid hexadecimal number and in the range 0000 to FFFF.
  380.  
  381. •• #ORG
  382.  
  383. The #ORG (origin) directive determines the address at which to begin 
  384. assembling the program. The format is:
  385.  
  386.                          #ORG  `address'
  387.  
  388. Where `address' must be a valid hexadecimal number in the range 0000 to 
  389. FFFF.  If there is more than one #ORG statement in a file the last one 
  390. read will be used as the starting address.  If no #ORG is specified the 
  391. assembler defaults to the address 0400.
  392.  
  393. •• #INCLUDE
  394.  
  395. The #INCLUDE directive specifies the name of a file that may only contain 
  396. comments, white space, and valid #EQU statements.  The format is:
  397.  
  398.                           #INCLUDE  `file'
  399.  
  400. Where `file' is the name of the file to be included.  If no pathname is 
  401. specified the file is assumed to be in the same folder as the assembler 
  402. application.  #INCLUDE is useful when a series of programs will be using 
  403. the same equates.  The assembler comes with the file STD.EQU which 
  404. contains equates for the more useful system monitor routines.  Any number 
  405. of #INCLUDE statements can be in a file.  The assembler will read all 
  406. the files before proceeding further.
  407.  
  408. •• Labels
  409.  
  410. Much of the power of an assembler comes from its ability to use labels 
  411. (symbols) in place of actual addresses.  This frees the programmer to 
  412. make alterations without concerning himself or herself with the effect on 
  413. the rest of the program.  For the MDP-8008 assembler a label 
  414. is defined as: any string of characters whose first character is a letter 
  415. of the alphabet (or `_')  and does not contain any white space (spaces or 
  416. tabs).  There is no practical limit to the length of a label.
  417. In use, a label may be substituted anywhere an address would belong.  
  418. When binding a label to an instruction precede it with a `.' (period):
  419.  
  420.                             lda >string
  421.                 .string     asc 'This is a string'
  422.  
  423. If the assembler encounters a multiply defined label it will use the 
  424. value of the first binding and ignoring subsequent definitions.
  425.  
  426. •• Mnemonics
  427.  
  428. Mnemonics are the three letter labels used by the assembler to represent 
  429. the actual microprocessor instructions.  It is far easier to remember that 
  430. LDA means to `load the accumulator' than to remember the hexadecimal 
  431. number A9.  A complete outline of the instruction set for the MDP-8008 
  432. microprocessor is given below.  Many instructions permit multiple addressing 
  433. modes which the assembler indicates in the operand field.  All 
  434. MDP-8008 mnemonics are three letters in length.  In addition to the 
  435. actual instructions the assembler recognizes two pseudo-mnemonics, ASC 
  436. and HEX.  These are used to assemble ASCII strings and hexadecimal data 
  437. into a file.  Their format is described in the section on _Special forms_.
  438.  
  439. •• Operands
  440.  
  441. The mnemonic determines the instruction while the operand (what the 
  442. instruction operates on) determines the address mode.  There are seven 
  443. possible addressing modes for the MDP-8008 and two assembler pseudo modes,
  444. each with a different operand format.  The modes are:
  445.  
  446.   * immediate
  447.   * implied
  448.   * absolute
  449.   * absolute indexed
  450.   * indirect absolute
  451.   * zero page
  452.   * relative
  453.   * > and < (pseudo)
  454.  
  455.  
  456. ••• Immediate mode
  457.  
  458. Immediate mode instructions are two bytes in length and are indicated 
  459. by a # as the first character of the operand field.  For example,
  460.  
  461. .nothing    lda #A4     ; put the value A4 into the accumulator
  462.  
  463. Note that there is no space between the # and the data.
  464.  
  465. ••• Implied mode
  466.  
  467. Implied mode is for single byte instructions that require no data.  
  468. Indicate this to the assembler by using no operand field:
  469.  
  470. .label      tax         ; transfer the accumulator to X
  471.  
  472.  
  473. ••• Absolute mode
  474.  
  475. Absolute mode instructions are three bytes in length (two bytes for an 
  476. address) and are indicated by a `$' preceding the address value.  If a 
  477. symbol is being used do not use a `$'.  For example,
  478.  
  479.             lda $1e39   ; load the value in $1e39 into A
  480.             sta data    ; and put it in the address bound to `data'
  481.  
  482.  
  483. ••• Absolute Indexed mode
  484.  
  485. Functionally the same as the absolute mode with the addition of the 
  486. characters `,x' at the end of the operand field.  Example,
  487.  
  488.             lda $1e39,x  ; load the value in $1e39+X into A
  489.             sta data,x   ; and put it in the address bound to `data'+X
  490.  
  491.  
  492. ••• Indirect Absolute mode
  493.  
  494. This mode is indicated by enclosing the address in parentheses and 
  495. appending `,x' at the end of the operand field.  Again, numerical addresses 
  496. must be prefixed by the `$' character.  Example,
  497.  
  498.             lda ($1e39),x   ; indirect load of A
  499.             sta (data),x    ; store indirectly
  500.  
  501.  
  502. ••• Zero Page mode
  503.  
  504. The microprocessor can take advantage of the implied 00 in addresses 
  505. below 0100.  This is called the zero page and instructions using it 
  506. require only two bytes instead of three.  The assembler forces all labels 
  507. to be two bytes so the only way to use zero page instructions is by 
  508. giving a numerical address.  Zero page is indicated by a `$' as absolute 
  509. mode is, but the address given is only two digits long:
  510.  
  511.             lda $1e     ; load the value in $1e into A
  512.  
  513.  
  514. ••• Relative mode
  515.  
  516. The assembler does not directly support relative mode branching 
  517. instructions.  All branches are assembled as absolute references.
  518.  
  519.  
  520. ••• > and < pseudo modes
  521.  
  522. The special pseudo modes > and < must be used with a label, not a 
  523. numerical address.  The > before the label is translated by the 
  524. assembler into an immediate mode instruction whose data byte is the most 
  525. significant byte of the address of the label.  The < translates into 
  526. the least significant byte of the address.  Examples,
  527.  
  528.             lda >string   ; load MSB of `string' into A
  529.             ldx <string   ; load LSB of `string' into X
  530. .string     asc 'a string' 
  531.  
  532.  
  533. ••• Comments and White Space
  534.  
  535. Comments start with a semicolon and continue to the end of the line.  Copious 
  536. use of comments is strongly encouraged.  White space is defined as blank 
  537. spaces or tab characters.  Blank lines are also permitted.  There must be 
  538. at least one space or tab between the parts of a line, but leading or 
  539. trailing white space is ignored.
  540.  
  541.  
  542. ••• Special Forms
  543.  
  544. The special forms used pertain to the ASC and HEX pseudo 
  545. instructions.  The ASC instruction expects a string of characters 
  546. delimited by single quotes.  The HEX instruction expects a series 
  547. of hexadecimal bytes, each of two digits (include leading zero) and with 
  548. no spaces between them.  Examples for each are,
  549.  
  550.             asc 'this is a string'  ; use single quotes
  551.             hex 000102030405060708  ; no spaces allowed
  552.  
  553. Both ASC and HEX are very useful for placing character data into a 
  554. program.
  555.  
  556.  
  557.  
  558. • Chapter 4  -  The System Monitor via Assembly Language
  559.  
  560. The simulator's built in system monitor program occupies the 2K of memory 
  561. from F800 to FFFF and contains the routines necessary to make it possible 
  562. to enter, execute, and modify machine language programs.  It also 
  563. contains a number of useful routines for printing strings and numbers, 
  564. entering data, and converting strings to numbers.  The file STD.EQU which 
  565. is included with the assembler contains equates to many of these subroutines.
  566. #INCLUDEing this file at the beginning of your programs will make these 
  567. routines available to you.  This chapter will discuss many of these routines, 
  568. giving examples and noting side-effects.
  569.  
  570.  
  571.                 _COUT   F876   Output character in A  
  572.   
  573. Description: Displays the character whose ASCII code is stored in the 
  574.              accumulator. 
  575. Registers altered: None. 
  576. Example:
  577.   
  578. lda #41    ; ASCII code for `A'
  579. jsr _cout  ; print the letter
  580.   
  581.  
  582.  
  583.                 _KEYIN   F87D   Input character from keyboard   
  584.  
  585. Description: Waits for a key to be pressed and places the ASCII value in 
  586.              the accumulator. 
  587. Registers altered: A. 
  588. Example:
  589.   
  590. jsr _keyin    ; get a character
  591. jsr _cout     ; and echo it back
  592.   
  593.  
  594.  
  595.                _INPUT    F87D   Input a line of text, with prompt  
  596.                _INPUT1   F889   Input a line of text, no prompt  
  597.    
  598. Description: Inputs a line of text. Characters are stored starting at location 
  599.              0300.  Backspace and delete keys work as normal. X holds the 
  600.              length on exit. 
  601. Registers altered: A, X. 
  602. Example:
  603.  
  604. jsr _input      ; get a line of text
  605. lda 0300        ; check first character
  606. cmp #41         ; compare to `A'
  607. beq Acommand    ; if so, then branch  
  608.  
  609.  
  610.  
  611.                _PRINT   F8D2   Print a null terminated string  
  612.   
  613. Description: Displays the null terminated string the address of which is in 
  614.              A (MSB) and X (LSB). 
  615. Registers altered: A, X. 
  616. Example:
  617.   
  618.          lda >string     ; get MSB of address of string
  619.          ldx <string     ; get LSB of address of string
  620.          jsr _print      ; print the string
  621. .string  asc 'a string'  ; a string
  622.          hex 00          ; null terminates string 
  623.  
  624.  
  625.  
  626.               _PRINTHEX   F8E9   Print A as a hexadecimal number  
  627.   
  628. Description: Display the accumulator as a two digit hexadecimal number. 
  629. Registers altered: A. 
  630. Example:
  631.   
  632.          lda #2D         ; load a number
  633.          jsr _printHex   ; displays `2D' on the screen  
  634.  
  635.  
  636.  
  637.           _PRINTWORD   F920   Print AX as a four digit hexadecimal number  
  638.   
  639. Description: Displays AX as a four digit number. A holds the high part, 
  640.              X holds the low. 
  641. Registers altered: A, X. 
  642. Example:
  643.   
  644.          lda #33         ; load the high part
  645.          ldx #44         ; load the low part
  646.          jsr _printWord  ; outputs `3344'
  647.            
  648.  
  649.  
  650.              _UPPER   F928   Convert a string to uppercase  
  651.   
  652. Description: Converts the null terminated string starting at the address in 
  653.              AX to uppercase. 
  654. Registers altered: A, X. 
  655. Example:
  656.   
  657.          lda >string     ; get MSB of address of string
  658.          ldx <string     ; get LSB of address of string
  659.          jsr _upper      ; make it uppercase
  660.          lda >string
  661.          ldx <string
  662.          jsr _print      ; print the string giving `A STRING'
  663. .string  asc 'a string'  ; a string
  664.          hex 00          ; null terminates string  
  665.  
  666.  
  667.  
  668.              _KILLB   F952   Remove the blanks from a string  
  669.   
  670. Description: Removes the blanks from the null terminated string that starts 
  671.              at the address in AX. 
  672. Registers altered: A, X. 
  673. Example:
  674.   
  675.          lda >string     ; get MSB of address of string
  676.          ldx <string     ; get LSB of address of string
  677.          jsr _killB      ; remove blanks
  678.          lda >string
  679.          ldx <string
  680.          jsr _print      ; outputs 'astring'
  681. .string  asc 'a string'  ; a string
  682.          hex 00          ; null terminates string
  683.   
  684.  
  685.  
  686.  
  687.              _LENGTH   F989   Find the length of a string  
  688.   
  689. Description Returns in X the length of the null terminated string pointed to 
  690.             by 06 and 07. 
  691. Registers altered: A, X. 
  692. Example:
  693.   
  694.          lda >string     ; get MSB of address of string
  695.          ldx <string     ; get LSB of address of string
  696.          jsr _length     ; get length
  697.          txa             ; put in A
  698.          jsr _printHex   ; outputs `08'
  699. .string  asc 'a string'  ; a string
  700.          hex 00          ; null terminates string
  701.  
  702.  
  703.  
  704.  
  705.             _NUMBER   F9DD   Convert a string to a number  
  706.   
  707. Description: Converts the null terminated string in AX into a 16-bit hexadecimal
  708.              number stored in 01 and 02. 
  709. Registers altered: A, X, and Y. 
  710. Example:
  711.  
  712.         #equ text 0300   ; text input buffer
  713.          jsr _input      ; get a number
  714.          lda >text       
  715.          ldx <text
  716.          jsr _number     ; convert it
  717.          lda $01
  718.          ldx $02
  719.          jsr _printWord  ; display it
  720.   
  721.  
  722.  
  723.             _REG   FF7F   Display current register values  
  724.   
  725. Description: Displays the current register values. 
  726. Registers altered: None. 
  727. Example:
  728.   
  729.          jsr _reg        ; output registers
  730.   
  731.  
  732.  
  733.  
  734.             _BLANKS   FFD8   Output blank spaces  
  735.   
  736. Description: Displays blank spaces, count in X. 
  737. Registers altered: A, X. 
  738. Example:
  739.   
  740.          ldx #0D         ; set up for 13 blanks
  741.          jsr _blanks     ; and print them
  742.  
  743.  
  744.  
  745. • Chapter 5  -  Glossary
  746.  
  747.  
  748.  
  749. Accumulator - is the register that the microprocessor uses for math 
  750. and logic functions.
  751.   
  752. Address mode - refers to the way in which a particular microprocessor 
  753. instruction uses the computer's memory.  The MDP-8008 has seven possible 
  754. address modes though not all modes are available to each instruction. 
  755.  
  756. ASCII - stands for American Standard Code for Information 
  757. Interchange. It is a method for coding the alphabet and other symbols in 
  758. a machine usable form.  The letter `A' has an ASCII value of 65. 
  759.  
  760. Assembler - translates programs written using mnemonics and labels into 
  761. pure machine code for use by the microprocessor.  
  762.  
  763. Bit - is the smallest unit of information a computer can use.  It is 
  764. a single binary digit, 0 or 1, on or off.  
  765.  
  766. Byte - is a series of 8 bits and is the smallest unit of memory for 
  767. most computers.  A single ASCII character occupies one byte of memory. 
  768.  
  769. Equate - binds a symbol to an address.  It is similar to defining a 
  770. constant in other programming languages.  For example, "#equ  start  
  771. 0400" will bind the symbol `start' to the address 0400. 
  772.  
  773. Hexadecimal - Base 16 number system.  Digits range from 0 through 9 and 
  774. A through F with A=10 and F=15.  Most machine code programming is 
  775. done in hexadecimal.  The MDP-8008 assembler assumes all numbers to be 
  776. hexadecimal.
  777.   
  778. Include file - is a file containing equates that may be included in 
  779. an assembly language program.  The file STD.EQU is included with the 
  780. assembler and contains equates for useful monitor subroutines.
  781.  
  782. Label - is a character string associated with a machine address.  It 
  783. is identical in meaning to _symbol_.
  784.  
  785. List file - holds the assembly listing.  The listing gives the 
  786. assembled code along with the original source and optionally includes the 
  787. symbol table.
  788.  
  789. Machine code - is the native tongue of a microprocessor.  It is 
  790. purely numerical and is generally represented as hexadecimal numbers.
  791.  
  792. MDP-80 - is the name of the microcomputer simulator that runs 
  793. programs written in MDP-8008 machine code.
  794.  
  795. MDP-8008 - is the microprocessor for which the assembler generates 
  796. machine code.  It is the heart of the MDP-80 microcomputer simulator.
  797.  
  798. Monitor - is the program burned into the ROM of a microcomputer.  It 
  799. lets the user modify memory and run machine language programs.
  800.  
  801. Object file - is the output from the assembler. It contains machine 
  802. code in a format that is usable by the simulator.
  803.  
  804. Pseudo instructions - are instructions that while not part of the 
  805. actual microprocessor instruction set are simulated by the assembler.  
  806. The ASC and HEX instructions are pseudo instructions.
  807.  
  808. Register - is a single byte storage space on the microprocessor.  The 
  809. MDP-8008 has three user registers, the accumulator (A), the X, and Y.
  810.  
  811. Simulator - is the program that simulates the operations of a small 
  812. microcomputer.  
  813.  
  814. Source file - is the file that contains the assembly language 
  815. program. It is used by the assembler to generate the object file.
  816.  
  817. Symbol - see label above.
  818.  
  819. Symbol table - is a list of all of the symbols used in a particular 
  820. program and the address bound to that symbol.
  821.  
  822. Word - is the standard unit used by a particular microprocessor.  An 
  823. 8-bit microprocessor uses one byte words.  A 32-bit microprocessor uses 4 
  824. byte words.  In the assembler and simulator, a word generally refers to a 
  825. 16-bit, or 2 byte, value.
  826.  
  827.  
  828. • Chapter 6  -  MDP-8008 Reference
  829.  
  830. The MDP-8008 microprocessor has 52 instructions and 7 addressing modes.  
  831. A summary of the MDP-8008 instruction set is given in the Simulator User's
  832. Manual.
  833.  
  834. •• MDP-8008 addressing modes
  835.  
  836. An instruction's addressing mode determines the way in which the 
  837. instruction will access and use memory.  The seven modes supported by the 
  838. MDP-8008 are implied, immediate, absolute, absolute indexed, zero page, 
  839. relative, and indirect indexed.
  840.  
  841.  Implied addressing 
  842.  
  843. The implied address in implied addressing is the accumulator.  Implied 
  844. mode is used by single byte instructions that only act on the accumulator 
  845. and do not reference memory.
  846.  
  847.  Immediate addressing 
  848.  
  849. The value used in immediate mode addressing is the next byte of the 
  850. program, or the first operand.  The target of the instruction is one of 
  851. the microprocessor's registers.  For example, LDA #FF loads the 
  852. accumulator with the immediate value FF.  
  853.  
  854.  Absolute addressing
  855.  
  856. An 8-bit microprocessor like the MDP-8008 can access a total of 65536 
  857. memory locations.  It therefore takes two bytes to represent the address 
  858. of any memory location.  Absolute addressing uses two operand bytes (the 
  859. first two bytes of the program following the byte containing the opcode) 
  860. to represent the address of a memory location.  For example, STA $1E37 will 
  861. store the contents of the accumulator in memory location 1E37.
  862.  
  863.  Absolute indexed addressing
  864.  
  865. Similar to absolute addressing, absolute indexed addressing uses as a 
  866. target address the value obtained when the address represented by the 
  867. operand bytes is added to the current value of the X register.  If the X 
  868. register contains 14 and the instruction is STA $1E38,X the contents of the 
  869. accumulator will be stored in location 1E38 + 14 = 1E4C.  Absolute indexed 
  870. addressing is particularly useful when dealing with lists.
  871.  
  872.  Indirect indexed addressing
  873.  
  874. The target address in indirect index addressing is found by taking the 
  875. absolute address in the operands, reading the two byte address that 
  876. starts at the given address and adding the contents of the X register to 
  877. get the final address.  For example, suppose the instruction being 
  878. executed (in assembly form) is LDA ($2E33),X.  If the values stored 
  879. in memory locations 2E33 and 2E34 are 14 and 1C and the current value of 
  880. the X register is A4 then the accumulator will be loaded with the contents 
  881. of location 141C + A4 = 14C0.
  882.  
  883.  Zero page addressing 
  884.  
  885. Zero page addressing takes advantage of the fact that the first 256 
  886. memory locations can be addressed in a single byte (00 to FF).
  887. Therefore, all instructions using the zero page are only two bytes long, 
  888. which can add up to a significant savings if frequently used locations 
  889. are in the zero page.
  890.  
  891.  Relative addressing 
  892.  
  893. Only the branch instructions use relative addressing.  Instead of 
  894. specifying an absolute location in memory, a relative address is a 
  895. positive or negative offset from the current address.  The use of 
  896. relative addressing allows one to write code that will run at any 
  897. location in memory.  Relative addressing uses one operand and as a result 
  898. can reference locations that are -128 to +127 bytes from the current 
  899. location.  The MDP-8008 assembler does not support relative addressing.
  900.  
  901.  
  902. •• MDP-8008 instruction names
  903.  
  904.  
  905. Label  Name
  906. --------------------------------------
  907.  ADC   Add to accumulator with carry               
  908.  AND   AND accumulator with memory                 
  909.  BCC   Branch on carry clear                       
  910.  BCS   Branch on carry set                         
  911.  BEQ   Branch on equal or zero                     
  912.  BGT   Branch on greater than                      
  913.  BLT   Branch on less than                         
  914.  BNE   Branch on not equal or not zero             
  915.  BNG   Branch on negative set                      
  916.  BPL   Branch on positive (not negative)           
  917.  BRA   Unconditional relative branch               
  918.  BRK   Break                                       
  919.  CLC   Clear carry flag                            
  920.  CMP   Compare accumulator to memory               
  921.  CPX   Compare X register to memory                
  922.  CPY   Compare Y register to memory                
  923.  DCA   Decrement accumulator by one                
  924.  DEC   Decrement memory by one                     
  925.  DEX   Decrement X register by one                 
  926.  DEY   Decrement Y register by one                 
  927.  EOR   Exclusive-OR accumulator with memory        
  928.  INA   Increment accumulator by one                
  929.  INC   Increment memory by one                     
  930.  INX   Increment X register by one                 
  931.  INY   Increment Y register by one                 
  932.  JMP   Jump to address                             
  933.  JSR   Jump to subroutine at address               
  934.  LDA   Load the accumulator with memory            
  935.  LDX   Load the X register with memory             
  936.  LDY   Load the Y register with memory             
  937.  LSH   Bit shift accumulator left, no carry        
  938.  NOP   No operation                                
  939.  ORA   OR accumulator with memory                  
  940.  PHA   Push accumulator on stack                   
  941.  PHP   Push processor status on stack              
  942.  PLA   Pull accumulator from stack                 
  943.  PLP   Pull processor status from stack            
  944.  ROL   Rotate accumulator to the left with carry   
  945.  ROR   Rotate accumulator to the right with carry  
  946.  RSH   Bit shift accumulator right, no carry       
  947.  RTS   Return from subroutine                      
  948.  SBC   Subtract memory from accumulator with carry 
  949.  SEC   Set carry flag                              
  950.  STA   Store accumulator in memory at address      
  951.  STX   Store X register in memory at address       
  952.  STY   Store Y register in memory at address       
  953.  TAX   Transfer accumulator to X register          
  954.  TAY   Transfer accumulator to Y register          
  955.  TSX   Transfer stack pointer to X register        
  956.  TXA   Transfer X register to accumulator          
  957.  TXS   Transfer X register to stack pointer        
  958.  TYA   Transfer Y register to accumulator          
  959.  
  960.